
  function ValidateRegistration() {
     // Variabili associate ai campi del form_register
     var username = document.form_register.username.value;
     var email = document.form_register.email.value;
     var email_confirm = document.form_register.email_confirm.value;
     var password = document.form_register.password;
     var first_name = document.form_register.first_name.value;
     var last_name = document.form_register.last_name.value;
     var birthdate = document.form_register.birthdate.value;
     var address = document.form_register.address.value;
     var answer = document.form_register.answer.value;
     var errorLog=document.getElementById("register_error_log");
     
     // Espressione regolare dell’email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        //Effettua il controllo sul campo NOME
        if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           errorLog.innerHTML='Insert a correct email into email.'
           document.form_register.email.select();
           return false;
        }else if (!email_reg_exp.test(email_confirm) || (email_confirm == "") || (email_confirm == "undefined")) {
           errorLog.innerHTML='Insert a correct email into email_confirm.'
           document.form_register.email_confirm.select();
           return false;
        }
        else if (email_confirm.value != email.value) {
           errorLog.innerHTML='Email not equals.';
           document.form_register.email.focus();
           return false;
        }
        else if ((username== "") || (username.value == "undefined")) {
           errorLog.innerHTML='Insert the username.';
           document.form_register.username.focus();
           return false;
        }
        //Effettua il controllo sul campo PASSWORD
        else if ((password[0].value == "") || (password[0].value == "undefined")) {
           errorLog.innerHTML='Insert the password.';
           document.form_register.password[0].focus();
           return false;
        }
        else if ((password[1].value == "") || (password[1].value == "undefined")) {
           errorLog.innerHTML='Insert the password.';
           document.form_register.password[1].focus();
           return false;
        }
        else if (password[0].value != password[1].value) {
           errorLog.innerHTML='Password not equals.';
           document.form_register.password[0].focus();
           return false;
        }
        else if
        ((first_name== "") || (first_name == "undefined")) {
           errorLog.innerHTML='Insert the name.';
           document.form_register.first_name.focus();
           return false;
        }
        //Effettua il controllo sul campo COGNOME
        else if ((last_name == "") || (last_name== "undefined")) {
           errorLog.innerHTML='Insert the last name.';
           document.form_register.last_name.focus();
           return false;
        }
        //Effettua il controllo sul campo DATA DI NASCITA
        else if (document.form_register.birthdate.value.substring(2,3) != "/" ||
           document.form_register.birthdate.value.substring(5,6) != "/" ||
           isNaN(document.form_register.birthdate.value.substring(0,2)) ||
           isNaN(document.form_register.birthdate.value.substring(3,5)) ||
           isNaN(document.form_register.birthdate.value.substring(6,10))) {
             errorLog.innerHTML='Insert the birthdate like gg/mm/aaaa';
              document.form_register.birthdate.value = "";
              document.form_register.birthdate.focus();
              return false;
        }
        else if (document.form_register.birthdate.value.substring(0,2) > 31) {
           errorLog.innerHTML='The day must be less then 32';
           document.form_register.birthdate.select();
           return false;
        }
        else if (document.form_register.birthdate.value.substring(3,5) > 12) {
           errorLog.innerHTML='The month must be less then 13';
           document.form_register.birthdate.value = "";
           document.form_register.birthdate.focus();
           return false;
        }
        else if (document.form_register.birthdate.value.substring(6,10) < 1900) {
           errorLog.innerHTML='The year must be more then 1900';
           document.form_register.birthdate.value = "";
           document.form_register.birthdate.focus();
           return false;
        }
        //Effettua il controllo sul campo TELEFONO
        else if ((address== "") || (address== "undefined")) {
           errorLog.innerHTML='Insert your address';
           document.form_register.address.focus();
           return false;
        }
        else if
        ((answer== "") || (answer== "undefined")) {
           errorLog.innerHTML='Insert the answer for the captcha.';
           document.form_register.answer.focus();
           return false;
        }
        //INVIA IL form_register
        else {
           document.form_register.submit();
        }
  }
